import pymysql
def select(sql,par="",mode="all",size=0):
    con=pymysql.connect(host="localhost",user="root",password="123456",database="bank",charset='utf8')
    cursor = con.cursor()
    if par !="":
        cursor.execute(sql,par)
    else:
        cursor.execute(sql)

    if mode=="all":
        return  cursor.fetchall()
    elif mode=="one":
        return  cursor.fetchone()
    elif mode=="many":
        return  cursor.fetchmany(size=size)
    # cursor.fetchone()
    # cursor.fetchall()
    # cursor.fetchmany(size=size)
    cursor.close()
    con.close()
def insert(sql,par):
    con = pymysql.connect(host="localhost", user="root", password="123456", database="bank",charset='utf8')
    cursor = con.cursor()
    cursor.execute(sql,par)
    con.commit()
    print("更新成功")
    # cursor.fetchone()
    # cursor.fetchall()
    # cursor.fetchmany(size=size)
    cursor.close()
    con.close()
def update(sql,par):
    con = pymysql.connect(host="localhost", user="root", password="123456", database="bank", charset='utf8')
    cursor = con.cursor()
    cursor.execute(sql, par)
    con.commit()
    print("更新成功")
    cursor.close()
    con.close()
def count_account():
    sql='select count(*) from user where account'
    return select(sql,mode="one")[0]